package cn.lccabc.user.service;

import cn.lccabc.common.utils.SecurityUtils;
import cn.lccabc.user.dao.UserMapper;
import cn.lccabc.user.entity.User;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by L on 2018/4/7.
 */
@Service(value = "userServiceImpl")
public class UserServiceImpl implements UserService {

    private Log log = LogFactory.getLog(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional
    public int creatUser(User user) throws Exception {
        try {
            user.setPassword(SecurityUtils.encrptyPassword(user.getPassword()));
            userMapper.insertSelective(user);
        } catch (Exception e) {
            log.error("添加用户异常",e);
            throw e;
        }
        return 0;
    }

    @Override
    public User findUserByUserName(String username) {
        User user = userMapper.selectByUsername(username);
        return user;
    }

    @Override
    public User findByUsernameShiro(String username) {
        User user = userMapper.selectByUsernameShiro(username);
        return user;
    }
}
